package com.ruoyi.system.controller;



import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.uuid.UUID;
import com.ruoyi.system.domain.YbssAddress;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.system.service.IYbssAddressService;

import java.util.List;
import java.util.stream.Collectors;


/**
 * 地址查看Controller
 * 
 * @author ruoyi
 * @date 2021-11-08
 */
@RestController
@RequestMapping("/address/userAddress")
public class YbssAddressController extends BaseController
{
    @Autowired
    private IYbssAddressService ybssAddressService;


    /**
     * 获取街道及所属社区
     * @return
     */
    @GetMapping("/treeselect")
    public AjaxResult getBelongingCommunity(){
        return AjaxResult.success(ybssAddressService.getBelongingCommunity());
    };

    /**
     * 模糊查询
     * @param completeAddress
     * @return
     */
    @PreAuthorize("@ss.hasPermi('address:userAddress:query')")
    @GetMapping(value = "/s/{completeAddress}")
    public AjaxResult getAddressIndex(@PathVariable("completeAddress")  String completeAddress){
        return AjaxResult.success(ybssAddressService.getAddressIndex(completeAddress));
    }

    /**
     * 查询全部
     * @return
     */
    @GetMapping("/selectAll")
    public AjaxResult selectAll(){
        return AjaxResult.success(ybssAddressService.selectAll());
    }


    /**
     * 修改
     * @return
     */
    @PostMapping("/u/updataList")
    public AjaxResult updatelist(@RequestBody YbssAddress ybssAddress){
        return AjaxResult.success(ybssAddressService.updatelist(ybssAddress));
    }


    /**
     * 删除
     * @return
     */
    @DeleteMapping(value = "/{ybssId}")
    public AjaxResult deleteById(@PathVariable("ybssId") String ybssId){
        return AjaxResult.success(ybssAddressService.getdeleteById(ybssId));
    }

    /**
     * 下拉框
     * @return
     */
    @GetMapping("/a/selectBybelongingCommunity")
    public AjaxResult selectBybelongingCommunity(){
        return AjaxResult.success(ybssAddressService.selectBybelongingCommunity());
    }

    /**
     * 新增
     * @param ybssAddress
     * @return
     */
    @PostMapping("/insertdatalist")
    public AjaxResult insertdatalist(@RequestBody YbssAddress ybssAddress){
        String ybssId = UUID.randomUUID().toString();
        ybssAddress.setYbssId(ybssId);
        return AjaxResult.success(ybssAddressService.insertdatalist(ybssAddress));
    }

    /**
     * 节点查询
     * @param
     * @return
     */
    @PreAuthorize("@ss.hasPermi('address:userAddress:query')")
    @PostMapping("/getTreeIndex")
    public AjaxResult getTreeIndex(@RequestBody List<String> asdid){
        String count=asdid.stream().map(str->"'"+str.substring(str.indexOf("_")+1)+"'").collect(Collectors.joining(","));
        return AjaxResult.success(ybssAddressService.getTreeIndex(count));
    }

}
